package com.hit.cmsService.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hit.cmsService.entity.CrmBanner;
import com.hit.cmsService.service.CrmBannerService;
import com.hit.commonUtils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-13
 */
@RestController
@RequestMapping("/cmsService/bannerAdmin")
@CrossOrigin
public class BannerAdminController {
    @Autowired
    private CrmBannerService crmBannerService;

    @ApiOperation(value = "获取banner分页列表")
    @GetMapping("getList/{page}/{limit}")
    public R getList(@PathVariable long page, @PathVariable long limit){
        Page<CrmBanner> pageParam=new Page<>(page,limit);
        crmBannerService.page(pageParam,null);
        return R.ok().data("items",pageParam.getRecords()).data("total",pageParam.getTotal());

    }

    @ApiOperation(value = "根据id获取banner")
    @GetMapping("getById/{id}")
    public R get(@PathVariable String id){
        CrmBanner crmBanner=crmBannerService.getById(id);
        return R.ok().data("item",crmBanner);
    }

    @ApiOperation(value = "添加banner")
    @PostMapping("save")
    public R save(@RequestBody CrmBanner banner){
        crmBannerService.save(banner);
        return R.ok();
    }

    @ApiOperation(value = "修改banner")
    @PostMapping("update")
    public R update(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }

    @ApiOperation(value = "根据id删除banner")
    @DeleteMapping("delete/{id}")
    public R remove(@PathVariable String id){
        crmBannerService.removeById(id);
        return R.ok();
    }
}

